<template>
	<view class="mainpadding" style="padding-bottom: 150rpx;">
		<view class="mainpadding ffffff radius">
			<view class="xiahuaxian">
				<view class="flexbetween">
					<view class="">
						<text class="bigtext xiaohei fonweight">{{convertDate(currentdate)}}（{{getCurrentDayOfWeek(currentdate)}}）{{sendtime}}</text>
						<text class="ershiba xiaohui margin_left1">出发</text>
					</view>
					<text class="bigtext xiaolan fonweight"><text class="smalltext xiaolan">￥</text>{{dataAll.tourist.price}}</text>
				</view>
				<view class="margin_top">
					<text class="lvdian margin_right2"></text>
					<text class="xiaohei ershiba ">{{dataAll.start_tourist_site.address}}</text>
				</view>
				<view class="margin_top">
					<text class="huangdian margin_right2"></text>
					<text class="xiaohei ershiba ">{{dataAll.end_tourist_site.address}}</text>
				</view>
			</view>
			<view class="flexleft margin_top xiaohui ershiba" @click="callphone(dataAll.tourist_time.tel)">
				<u-icon name="phone-fill" color="#2979ff" size="14"></u-icon>
				<view class="xiaolan">随车电话</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween" @click="checkperson">
				<view class="xiaohei sanshier fonweight">选择乘车人</view>
				<view class="flexright">
					<view class="xiaohui ershil">每单可订购4张成人票</view>
					<u-icon name="arrow-right" color="#333" size="14"></u-icon>
				</view>
			</view>
			<view class=" margin_top" :class="index<2?'xiahuaxian':''" v-for="(item,index) in dataAll.passengers" :key="item.id">
				<view>
					<text class="xiaolv sanshier margin_right3">{{item.name}}</text>
					<text class="xiaohei lable">{{item.datatype==1?'成人':'儿童'}}</text>
				</view>
				<view class="xiaohui margin_top ershil">证件号：{{item.idcard}}</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="titletext hei_text bold">联系人</view>
				<input type="text" class="textright xiaohei ershiba" placeholder="请输入联系人姓名" v-model="lxname"/>
			</view>
			<view class="flexbetween margin_top">
				<view class="titletext hei_text bold">联系电话</view>
				<input type="number" class="textright xiaohei ershiba" placeholder="请输入联系电话" v-model="lxtel"/>
			</view>
			<view class="titletext margin_top hei_text bold">备注</view>
			<textarea class="margin_top" style="width: 100%;height: 100rpx;" placeholder="请输入留言信息给卖家" v-model="remarks"></textarea>
		</view>
		<view class="margin_top xiaohui ershiba">
			<view class="">温馨提示：</view>
			<text>{{orderwxts}}</text>
		</view>
		<view class="margin_top1 xiaohui ershiba">
			<view class="">购买须知：</view>
			<text>{{buypiao_xz}}</text>
		</view>
		<view class="gudingdb mainpadding flexbetween ffffff">
			<view class="flexleft titletext bold">
				<view class="xiaohei">合计：</view>
				<view class="xiaolan fonweight">￥{{dataAll.payinfo.pay_price}}</view>
			</view>
			<view class="bigbtn" style="width: 35%;border-radius: 50rpx;" @click="submit()">提交订单</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tourist_time_id:"",
				start_tourist_site_id:"",
				end_tourist_site_id:"",
				tourist_id:"",
				dataAll:{},
				passengers_ids:"",
				currentdate:"",
				lxname:"",
				lxtel:"",
				remarks:"",
				sendtime:"",
				buypiao_xz:"",
				orderwxts:""
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.tourist_time_id = data.tourist_time_id
			this.start_tourist_site_id = data.startId
			this.end_tourist_site_id = data.endId
			this.tourist_id = data.tourist_id
			this.currentdate = data.currentdate
			this.sendtime = data.sendtime
			uni.$on("checkInfo",data=>{
				this.passengers_ids = data
			})
			this.getInfo()
		},
		onShow() {
			this.getOrder()
		},
		onUnload() {
			uni.$off("checkInfo")
		},
		methods: {
			submit(){
				if(this.passengers_ids==""){
					httpRequest.toast("请选择乘车人")
					return false
				}
				if(this.lxname==""){
					httpRequest.toast("请输入联系人姓名")
					return false
				}
				if(this.lxtel==""){
					httpRequest.toast("请输入联系电话")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/Travelcl/touristOrderSubmit','POST',{
					 tourist_time_id:this.tourist_time_id,
					 start_tourist_site_id:this.start_tourist_site_id,
					 end_tourist_site_id:this.end_tourist_site_id,
					 tourist_id:this.tourist_id,
					 passengers_ids:this.passengers_ids,
					 cc_time:this.currentdate,
					 lxname:this.lxname,
					 lxtel:this.lxtel,
					 remarks:this.remarks,
				}).then(res => {
					uni.hideLoading()
					uni.redirectTo({
						url:"/pages/index/zhifu?order_id="+res.data.order_id+"&pay_price="+res.data.pay_price
					})
				})
			},
			getOrder(){
				httpRequest.request('/api/Travelcl/touristOrderSure','POST',{
					 tourist_time_id:this.tourist_time_id,
					 start_tourist_site_id:this.start_tourist_site_id,
					 end_tourist_site_id:this.end_tourist_site_id,
					 tourist_id:this.tourist_id,
					 passengers_ids:this.passengers_ids
				}).then(res => {
					this.dataAll = res.data
				})
			},
			getInfo(){
				httpRequest.request('/api/index/getConfigInfoItem','POST',{
					 pidtype:"about_set",
					 type:"buypiao_xz"
				}).then(res => {
					this.buypiao_xz = res.data
				})
				httpRequest.request('/api/index/getConfigInfoItem','POST',{
					 pidtype:"about_set",
					 type:"orderwxts"
				}).then(res => {
					this.orderwxts = res.data
				})
			},
			checkperson(){
				uni.navigateTo({
					url:"/pages/mine/chengcher?type=1&passengers_ids="+this.passengers_ids+"&tjnum=4"
				})
			},
			// yyyy-mm-dd转换mm/dd
			convertDate(dateString) {
				const parts = dateString.split('-');
				const year = parts[0]; // 不需要转换
				const month = parts[1]; // 需要转换为 mm/dd 格式
				const day = parts[2]; // 需要转换为 mm/dd 格式
				// 使用两位数表示月份和日期
				return `${month.padStart(2, '0')}月${day.padStart(2, '0')}日`;
			},
			// 年月日转换周几
			getCurrentDayOfWeek(val) {
				const today = new Date(val);
				const dayOfWeek = today.getDay();
				const daysOfWeek = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
				return daysOfWeek[dayOfWeek];
			}
		}
	}
</script>

<style>
.lable {
		padding: 0 8rpx;
		border: 1rpx solid #999;
		font-size: 20rpx;
	}
</style>
